<template>
	<view>
		<input type="text" id="input" placeholder="请输入链接" :value="item" @input="onInput" />
		<button type="default" @click="btn()">解析</button>
		<!-- <video :src="list" controls v-if="self"></video> -->
		<video v-if="self" id="theVideo" style="width: 100%;" class="video-player" preload="auto" :src="list" type="video/mp4"  controls 
			webkit-playsinline="true" playsinline="true" x5-video-player-type="h5"
			x5-video-player-fullscreen="portraint">
		</video>
		 <view class="uni-padding-wrap uni-common-mt" v-if="ben">
		            <view class="progress-box">
		                <progress :percent="num" show-info stroke-width="3" />
		            </view>
		        </view>
		<button type="default" @click="down()" v-if="self">下载</button>
		
	</view>
</template>

<script>
	import clipboard from "../../js_sdk/dc-clipboard/clipboard.js"
	import $ from 'jquery'
	// import moveVerify from "@/components/helang-moveVerify/helang-moveVerify.vue"
	import axios from 'axios'
	
	export default {
		 // components: {
		 //        "move-verify":moveVerify
		 //    },
		data() {
			return {
				 resultData:{},
				item: "",
				list: "",
				bb:"",
				self: false,
				ben:false,
				num:0
			}
		},
		methods: {
			btn1(){
				console.log(55668)
			},
			onInput(e){
				var aaa=this
				this.bb=e.detail.value
			},
			btn() {
						var abc=this
			
							uni.request({
							    url: 'https://v2.alapi.cn/api/video/url', 
							    data: {
							      url:this.bb,
								  token:"SvTkUJqVBqdWdGM6"
							    },	
							    success: (res) => {
							       let data=  res.data
								   abc.list=data.data.video_url
								   	this.self = true
								 console.log(res)
							    },
								fail() {
									console.log(1111)
								}
							});
							
							
						},
			down(){
				 console.log(this.list)
				 if(this.num==100){
					 uni.showToast({
					 	title: '视频以下载',
					 	duration: 2000
					 });
					 return false
				 }
				 	this.ben = true
		const downloadTask = uni.downloadFile({
		    url: this.list, //仅为示例，并非真实的资源
		    success: ({statusCode,tempFilePath}) => {
		        if (statusCode === 200) {
		            uni.saveVideoToPhotosAlbum({
		                                   filePath: tempFilePath,
		                                   success: function () {
		                                     uni.showToast({
		                                     	title: '已保存在相册',
		                                     	duration: 2000
		                                     });
		                                   }
		                               });
		       
		        }
		    }
		});
		
		downloadTask.onProgressUpdate((res) => {
		    console.log('下载进度' + res.progress);
		    // console.log('已经下载的数据长度' + res.totalBytesWritten);
		    // console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
		this.num=res.progress
		    // 测试条件，取消下载任务。
		    if (res.progress == 100) {
		      uni.showToast({
		      	title: '下载完成',
		      	duration: 2000
		      });
		    }
		});
			},

		},
		mounted() {
			uni.getClipboardData({
			    success: function (res) {
			       let bb=JSON.stringify(res.data)
				   this.item=bb
				   console.log(1111,this.item)
			    }
			});
// $('#tempForClip').val(txt);
// var temp=$('#tempForClip').val();
// window.clipboardData.setData("Text",temp);
		}
	}
</script>

<style>
	#input {
		border: 1px solid #000000;
		height: 45px;
		margin-top: 40rpx;
	}
</style>
